home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
C-H
/
Finder Progress Pascal.cpt
/
Finder Progress Pascal
/
Routines.p
< prev
Wrap
Text File
|
1993-01-03
|
5KB
|
171 lines
unit Routines; {from Finder Progress by Joe Zobkiw, Pascal translation by Mike Epstein}
interface
const
kGrayProgressColorRed = 17476;
kGrayProgressColorGreen = 17476;
kGrayProgressColorBlue = 17476;
kPurpleProgressColorRed = -13108; {52428 as an integer}
kPurpleProgressColorGreen = -13108; {52428 as an integer}
kPurpleProgressColorBlue = -1; {65535 as an integer}
kAboutAlertID = 129;
kModalProgressDialogID = 128;
kDialogProgressItem = 1;
kColorBitDepth = 8;
procedure UpdateProgress (r: Rect; percentage: Integer; color: Boolean);
function DItemRect (dialog: DialogPtr; item: Integer): Rect;
function ColorQDIsPresent: Boolean;
function BitDepth: Integer;
implementation
{********************************************************************}
{ UpdateProgress}
{ }
{ draws the progress item, expects the port to be set properly.}
{ You can pass any parameters you like into this routine, it}
{ depends on the situation you plan on using it in. I decided}
{ to simply pass a Rect, percentage, and a color flag.}
{ }
{ this implementation draws the entire thermometer each time}
{ which will cause the cursor to flicker if you move it over the}
{ thermometer itself. i do this for a few reasons, one being I}
{ didn't want the overhead or hassle of allocating an offscreen}
{ pixmap or bitmap to provide flicker free animation, and secondly}
{ if we are drawing and a screensaver goes on, when it kicks out}
{ again we will be sure to draw the entire thermometer immediately}
{ and not just a portion of it.}
{ }
{********************************************************************}
procedure UpdateProgress (r: Rect; percentage: Integer; color: Boolean);
var
rgb: RGBColor;
theRect, fillRect, emptyRect: Rect;
savePen: PenState;
theForeColor: RGBColor;
offset: Integer;
begin
theRect := r;
fillRect := r;
emptyRect := r;
{save the pen state and color}
GetPenState(savePen);
if color then
GetForeColor(theForeColor);
PenNormal;
{first frame the rectangle}
if color then
begin
rgb.red := 0;
rgb.green := 0;
rgb.blue := 0;
RGBForeColor(rgb);
end
else
ForeColor(blackColor);
FrameRect(theRect);
{figure out the percentage}
InsetRect(theRect, 1, 1);
InsetRect(fillRect, 1, 1);
InsetRect(emptyRect, 1, 1);
offset := Round((theRect.right - theRect.left) * percentage / 100);
{first draw the filled in portion}
fillRect.right := fillRect.left + offset;
if color then
begin
rgb.red := kGrayProgressColorRed;
rgb.green := kGrayProgressColorGreen;
rgb.blue := kGrayProgressColorBlue;
RGBForeColor(rgb);
end
else
ForeColor(blackColor);
PaintRect(fillRect);
{now draw the unfilled portion}
emptyRect.left := fillRect.right + 1;
if color then
with rgb do
begin
{red := 32767;}
{green := 32767;}
{blue := 32767;}
red := kPurpleProgressColorRed;
green := kPurpleProgressColorGreen;
blue := kPurpleProgressColorBlue;
RGBForeColor(rgb);
end
else
ForeColor(whiteColor);
PaintRect(emptyRect);
{restore pen settings, colors, restore to black when not in color}
SetPenState(savePen);
if color then
RGBForeColor(theForeColor)
else
ForeColor(blackColor);
end;
{********************************************************************}
{ DItemRect}
{ }
{ returns the rectangle of a dialog item}
{ }
{********************************************************************}
function DItemRect (dialog: DialogPtr; item: Integer): Rect;
var
itemType: Integer;
itemHandle: Handle;
itemRect: Rect;
begin
GetDItem(dialog, item, itemType, itemHandle, itemRect);
DItemRect := itemRect;
end;
{********************************************************************}
{ ColorQDIsPresent}
{ }
{ returns true if color quickdraw is present, false otherwise}
{********************************************************************}
function ColorQDIsPresent: Boolean;
var
theWorld: SysEnvRec;
i: integer;
begin
i := SysEnvirons(1, theWorld);
ColorQDIsPresent := theWorld.hasColorQD;
end;
{********************************************************************}
{ BitDepth}
{ }
{ returns the bitdepth of the main monitor}
{********************************************************************}
function BitDepth: Integer;
var
bits: Integer;
mainDevice: GDHandle;
pixMap: PixMapHandle;
begin
bits := 1;
if ColorQDIsPresent then
begin
mainDevice := GetMainDevice;
pixMap := mainDevice^^.gdPMap;
bits := pixMap^^.pixelSize;
end;
BitDepth := bits;
end;
end.